/*
 * @FilePath: 聚光灯.js
 * @Author: 杜芬
 * @Date: 2024-04-15 22:15:45
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-04-16 21:43:09
 * Copyright: 2024 xxxTech CO.,LTD. All Rights Reserved.
 * @Descripttion: 页面
 */
import { scene, camera } from './utils/init'
import * as THREE from 'three'

// 目标：聚光灯（手电筒/舞台聚光灯）
// 作用：从一个点沿一个方向射出，距离越远，光锥尺寸越大，模拟手电筒/舞台聚光灯
// 步骤：
// 1. 创建 SpotLight 聚光灯对象，设置位置等添加到场景中
// 2. 创建 SpotLightHelper 聚光灯辅助对象（可选），辅助我们观察光源位置

function createFloor() {
  const geometry = new THREE.PlaneGeometry(10, 10)
  const material = new THREE.MeshStandardMaterial({
    color: 0xffffff,
    side: THREE.DoubleSide
  })
  const plane = new THREE.Mesh(geometry, material)
  plane.rotation.set(- Math.PI / 2, 0, 0)
  scene.add(plane)
}
function createLight() {
  // 环境光
  // const light = new THREE.AmbientLight(0xffffff, 1)
  // scene.add(light)

  // 点光源（灯泡）
  // const light = new THREE.PointLight(0xffffff, 1, 100);
  // light.position.set(3, 3, 3);
  // scene.add(light);

  // const pointLightHelper = new THREE.PointLightHelper(light, 1);
  // scene.add(pointLightHelper);

  // 平行光（太阳）
  // const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
  // directionalLight.position.set(3, 3, 3);
  // scene.add(directionalLight);

  // const helper = new THREE.DirectionalLightHelper(directionalLight, 1);
  // scene.add(helper);


  // 聚光灯（手电）
  const spotLight = new THREE.SpotLight(0xffffff, 1);
  spotLight.position.set(3, 3, 3);
  // 灯光的纹理（会把图片和聚光灯颜色混合后打在目标物体上）
  spotLight.map = new THREE.TextureLoader().load('image/desert.jpg');
  scene.add(spotLight)

  const spotLightHelper = new THREE.SpotLightHelper(spotLight);
  scene.add(spotLightHelper);
}

camera.position.set(5, 5, 5)
createFloor()
createLight()